﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SachOnlineLibrary.Public;
using SachOnlineLibrary.BLL;
public partial class UC_User_UCThemGioHangl : System.Web.UI.UserControl
{
    PhieuDatHangBLL addphieudathang = new PhieuDatHangBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        Sach item = new Sach();
        item = addphieudathang.LaySach(int.Parse(Request.QueryString.Get("MaSach").ToString()));
        int tong;
        if (Session["TONG"] == null)
        {
            Session["TONG"] = item.GiaTien;
        }
        else
        {
            tong = int.Parse(Session["TONG"].ToString());
            Session["TONG"] = item.GiaTien + tong;
        }
        List<Sach> listsach = new List<Sach>();
        if (Session["Cart"] == null)
        {
                    item.SoLuong = 1;
                    listsach.Add(item);
                    Session["Cart"] = listsach;
        }
        else
        {
                    bool flag = false;
                    listsach = (List<Sach>)Session["Cart"];
                    foreach (Sach s in listsach)
                    {
                        if (s.MaSach==item.MaSach)
                        {
                            s.SoLuong++;
                            flag=true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        item.SoLuong = 1;
                        listsach.Add(item);
                    }
                    Session["Cart"] = listsach;
         }
          Response.Redirect("Default.aspx");
    }

}